<!DOCTYPE html>
<html lang="en" xmlns:th="http://www.thymeleaf.org">
<head>
    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width, user-scalable=no, initial-scale=1.0, maximum-scale=1.0, minimum-scale=1.0">
    <title>编辑附件</title>
    <link href="/static/pengpai/component/pear/css/pear.css" rel="stylesheet">
</head>
<!--<body class="pear-container">-->
<body>
<form class="layui-form layui-col-xs6 layui-col-md4 layui-col-md-offset4" action="">
    <div class="layui-form-item">
        <label class="layui-form-label">文件名称:</label>
        <div class="layui-input-block">
            <input type="text" name="fileName" th:value="${attach.fileName}" required  lay-verify="required" placeholder="请输入输入框内容" autocomplete="off" class="layui-input">
        </div>
    </div>
    <div class="layui-form-item">
        <label class="layui-form-label">文件大小:</label>
        <div class="layui-input-block">
            <input type="text" name="fileSize" th:value="${attach.fileSize}" required  lay-verify="required" placeholder="请输入输入框内容" autocomplete="off" class="layui-input" readonly>
        </div>
    </div>
    <div class="layui-form-item">
        <div class="layui-card-body layui-row layui-col-space10">
            <div class="layui-form-label">是否为附件:</div>
            <div class="layui-input-block">
                <input type="radio" name="isAttach" value="1" title="是" th:checked="${attach.isAttach==1}">
                <input type="radio" name="isAttach" value="0" title="否" th:checked="${attach.isAttach==0}">
            </div>
        </div>
    </div>
    <div class="layui-form-item">
        <label class="layui-form-label">访问地址:</label>
        <div class="layui-input-block">
            <input type="text" name="visitUrl" th:value="${attach.visitUrl}" required  lay-verify="required" placeholder="请输入输入框内容" autocomplete="off" class="layui-input" readonly>
        </div>
    </div>
    <div class="layui-form-item">
        <label class="layui-form-label">文件格式:</label>
        <div class="layui-input-block">
            <input type="text" name="fileSuff" th:value="${attach.fileSuff}" required  lay-verify="required" placeholder="请输入输入框内容" autocomplete="off" class="layui-input">
        </div>
    </div>
    <div class="layui-form-item">
        <label class="layui-form-label">文件路径:</label>
        <div class="layui-input-block">
            <input type="text" name="filePath" th:value="${attach.filePath}" required  lay-verify="required" placeholder="请输入输入框内容" autocomplete="off" class="layui-input" readonly>
        </div>
    </div>
    <div class="layui-form-item">
        <label class="layui-form-label">上传用户:</label>
        <div class="layui-input-block">
            <input type="text" name="uploadUser" th:value="${attach.uploadUser}" required  lay-verify="required" placeholder="请输入输入框内容" autocomplete="off" class="layui-input" readonly>
        </div>
    </div>
    <div class="layui-form-item">
        <label class="layui-form-label">上传时间:</label>
        <div class="layui-input-inline">
            <input type="text" class="layui-input" name="dateString" id="timeElem" placeholder="yyyy-MM-dd HH:mm:ss" readonly>
        </div>
    </div>
    <div class="layui-form-item">
        <div class="layui-input-block">
            <button class="layui-btn" lay-submit lay-filter="attach-save">立即提交</button>
            <button type="reset" class="layui-btn layui-btn-primary">重置</button>
        </div>
    </div>
</form>
<script src="/static/pengpai/component/layui/layui.js"></script>
<script src="/static/pengpai/component/pear/pear.js"></script>
<script>
    layui.use(['form', 'jquery', 'popup', 'laydate'], function () {
        let form = layui.form;
        let $ = layui.jquery;
        let popup = layui.popup;
        var laydate = layui.laydate;

        laydate.render({
            elem: '#timeElem', //指定元素
            type: 'datetime',
            value: '[[${dateString}]]',
        });

        form.on('submit(attach-save)', function (data) {
            let roleIds = "";
            $('input[type=checkbox]:checked').each(function () {
                roleIds += $(this).val() + ",";
            });
            roleIds = roleIds.substr(0, roleIds.length - 1);
            data.field.roleIds = roleIds;

            $.ajax({
                url: '/webAttach/update',
                data: data.field,
                dataType: 'json',
                type: 'post',
                success: function (result) {
                    if (result.code == 200) {
                        popup.success(result.msg, function () {
                            // console.log(obj);
                            parent.layer.close(parent.layer.getFrameIndex(window.name));//关闭当前页
                            parent.layui.table.reload("user-table");
                        });
                    } else {
                        popup.failure(result.msg);
                    }
                }
            })
            return false;
        });
    })
</script>
</body>
</html>